import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { configParams } from '../storage-config';

@Injectable({
  providedIn: 'root'
})
export class ExwarehousmanageService {

  headers = configParams.headers;

  serviceUrls: any = {
    queryExwarehousListUrl: '/delivery/list', // 查询出库单list
    queryExwarehousDetailUrl: '/deliveryDetails/list', // 出库单 - 详情
    saveExwarehousUrl: '/delivery/save', // 出库单 - 新增
    editExwarehousUrl: '/delivery/update', // 出库单 - 编辑
    tovoidExwarehousUrl: '/deliveryDetails/nullify', // 出库单 - 作废
    updateDeliveryOrderInfoUrl: '/delivery/updateInformation', // 修改出库单
    deleteExwarehousUrl: '/delivery/delete', // 出库单 - 删除
    cancelLogisticsOrderUrl: '/delivery/cancel', // 出库单 - 取消物流单
    mergeExwarehousUrl: '/delivery/merge', // 出库单 - 合并
    auditExwarehousUrl: '/delivery/audit', // 出库单 审核
    exportExwarehousPickUrl: '/delivery/exportPicking', // 出库单 - 导出拣货信息
    notifyPickupUrl: '/delivery/noticeLogistics', // 出库单 - 通知快递取件
    queryStoreGoodsUrl: '/delivery/listWhGoods' // 根据仓库查询商品list
  };

  constructor(public httpClient: HttpClient) { }

  // 根据仓库查询商品list
  getStoreGoodsData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryStoreGoodsUrl, params, {headers: this.headers}).toPromise();
  }

  // 查询出库单list
  getExwarehousList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryExwarehousListUrl, params, {headers: this.headers}).toPromise();
  }
  
  // 查询出库单 详情
  getExwarehousDetailData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryExwarehousDetailUrl, params, {headers: this.headers}).toPromise();
  }

  /**
   * 新增 | 编辑 出库单
   * @param params 
   * @param type 0：新增 1：编辑
   * @returns 
   */
  updateExwarehousData(params: any, type: number = 0) {
    let url = type === 1 ? this.serviceUrls.editExwarehousUrl : this.serviceUrls.saveExwarehousUrl;
    return this.httpClient.post(url, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 作废
  tovoidExwarehousData(params: any) {
    return this.httpClient.post(this.serviceUrls.tovoidExwarehousUrl, params, {headers: this.headers}).toPromise();
  }

  // 修改出库单信息
  updateDeliveryOrderInfoData(params: any) {
    return this.httpClient.post(this.serviceUrls.updateDeliveryOrderInfoUrl, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 删除
  deleteExwarehousData(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteExwarehousUrl, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 取消物流单
  cancelLogisticsOrderData(params: any) {
    return this.httpClient.post(this.serviceUrls.cancelLogisticsOrderUrl, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 审核
  auditExwarehousData(params: any) {
    return this.httpClient.post(this.serviceUrls.auditExwarehousUrl, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 合并
  mergeExwarehousData(params: any) {
    return this.httpClient.post(this.serviceUrls.mergeExwarehousUrl, params, {headers: this.headers}).toPromise();
  }

  // 出库单 - 合并
  exportExwarehousPickData(params: any) {
    return this.httpClient.get(this.serviceUrls.exportExwarehousPickUrl, {params, responseType: 'blob', headers: this.headers}).toPromise();
  }

  // 出库单 - 通知取件
  notifyPickupData(params: any) {
    return this.httpClient.post(this.serviceUrls.notifyPickupUrl, params, {headers: this.headers}).toPromise();
  }
}



